package cn.csc.module.pay.controller.admin.rate;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.annotations.*;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.csc.framework.common.pojo.PageResult;
import cn.csc.framework.common.pojo.CommonResult;
import static cn.csc.framework.common.pojo.CommonResult.success;

import cn.csc.framework.excel.core.util.ExcelUtils;

import cn.csc.framework.operatelog.core.annotations.OperateLog;
import static cn.csc.framework.operatelog.core.enums.OperateTypeEnum.*;

import cn.csc.module.pay.controller.admin.rate.vo.*;
import cn.csc.module.pay.dal.dataobject.rate.PayJzbRateDO;
import cn.csc.module.pay.convert.rate.PayJzbRateConvert;
import cn.csc.module.pay.service.rate.PayJzbRateService;

@Api(tags = "管理后台 - 见证宝提现手续费率")
@RestController
@RequestMapping("/pay/jzb-rate")
@Validated
public class PayJzbRateController {

    @Resource
    private PayJzbRateService jzbRateService;

    @PostMapping("/create")
    @ApiOperation("创建见证宝提现手续费率")
    @PreAuthorize("@ss.hasPermission('pay:jzb-rate:create')")
    public CommonResult<Long> createJzbRate(@Valid @RequestBody PayJzbRateCreateReqVO createReqVO) {
        return success(jzbRateService.createJzbRate(createReqVO));
    }

    @PutMapping("/update")
    @ApiOperation("更新见证宝提现手续费率")
    @PreAuthorize("@ss.hasPermission('pay:jzb-rate:update')")
    public CommonResult<Boolean> updateJzbRate(@Valid @RequestBody PayJzbRateUpdateReqVO updateReqVO) {
        jzbRateService.updateJzbRate(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @ApiOperation("删除见证宝提现手续费率")
    @ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = Long.class)
    @PreAuthorize("@ss.hasPermission('pay:jzb-rate:delete')")
    public CommonResult<Boolean> deleteJzbRate(@RequestParam("id") Long id) {
        jzbRateService.deleteJzbRate(id);
        return success(true);
    }

    @GetMapping("/get")
    @ApiOperation("获得见证宝提现手续费率")
    @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class)
    @PreAuthorize("@ss.hasPermission('pay:jzb-rate:query')")
    public CommonResult<PayJzbRateRespVO> getJzbRate(@RequestParam("id") Long id) {
        PayJzbRateDO jzbRate = jzbRateService.getJzbRate(id);
        return success(PayJzbRateConvert.INSTANCE.convert(jzbRate));
    }

    @GetMapping("/list")
    @ApiOperation("获得见证宝提现手续费率列表")
    @ApiImplicitParam(name = "ids", value = "编号列表", required = true, example = "1024,2048", dataTypeClass = List.class)
    @PreAuthorize("@ss.hasPermission('pay:jzb-rate:query')")
    public CommonResult<List<PayJzbRateRespVO>> getJzbRateList(@RequestParam("ids") Collection<Long> ids) {
        List<PayJzbRateDO> list = jzbRateService.getJzbRateList(ids);
        return success(PayJzbRateConvert.INSTANCE.convertList(list));
    }

    @GetMapping("/page")
    @ApiOperation("获得见证宝提现手续费率分页")
    @PreAuthorize("@ss.hasPermission('pay:jzb-rate:query')")
    public CommonResult<PageResult<PayJzbRateRespVO>> getJzbRatePage(@Valid PayJzbRatePageReqVO pageVO) {
        PageResult<PayJzbRateDO> pageResult = jzbRateService.getJzbRatePage(pageVO);
        return success(PayJzbRateConvert.INSTANCE.convertPage(pageResult));
    }

    @GetMapping("/export-excel")
    @ApiOperation("导出见证宝提现手续费率 Excel")
    @PreAuthorize("@ss.hasPermission('pay:jzb-rate:export')")
    @OperateLog(type = EXPORT)
    public void exportJzbRateExcel(@Valid PayJzbRateExportReqVO exportReqVO,
              HttpServletResponse response) throws IOException {
        List<PayJzbRateDO> list = jzbRateService.getJzbRateList(exportReqVO);
        // 导出 Excel
        List<PayJzbRateExcelVO> datas = PayJzbRateConvert.INSTANCE.convertList02(list);
        ExcelUtils.write(response, "见证宝提现手续费率.xls", "数据", PayJzbRateExcelVO.class, datas);
    }

}
